package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.TwoTwoBean;
import com.pe1n.yangtaopai.page.detail.view.activity.DetailActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/11/28.
 */

public class MyActivityItemTwoItmRigthRecyclerAdapter extends RecyclerView.Adapter<MyActivityItemTwoItmRigthRecyclerAdapter.MyViewHolder>{
    private Context mContent;
    private List<TwoTwoBean.DataBean.AllranklistBean> intemOnerightListBean;

    public MyActivityItemTwoItmRigthRecyclerAdapter(Context mContent, List<TwoTwoBean.DataBean.AllranklistBean> intemOnerightListBean) {
        this.mContent = mContent;
        this.intemOnerightListBean = intemOnerightListBean;
    }

    @Override
    public int getItemCount() {
        return intemOnerightListBean.size();
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContent).inflate(R.layout.activity_item_two_item_laout,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        TwoTwoBean.DataBean.AllranklistBean bean=intemOnerightListBean.get(position);
        String urlString=bean.getImagePath();
        Glide.with(mContent)
                .load(urlString)
                .placeholder(R.drawable.place_holder)
                .into(holder.loadimageView);
        holder.LoadTextXiangqing.setText(bean.getProdName());
        holder.loadMoney.setText( "¥"+bean.getProdPrice());
        holder.loadXiaoliang.setText("上周日本销量"+bean.getSalesCount());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent=new Intent(mContent, DetailActivity.class);
                String id=intemOnerightListBean.get(position).getProdId();
                String name=intemOnerightListBean.get(position).getProdName();
                intent.putExtra("id",id);
                intent.putExtra("name",name);
                mContent.startActivity(intent);
            }
        });

    }



    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView loadimageView;
        private TextView LoadTextXiangqing,loadMoney,loadXiaoliang;
        public MyViewHolder(View itemView) {
            super(itemView);
            loadimageView= (ImageView) itemView.findViewById(R.id.image_activity_item_two);
            LoadTextXiangqing= (TextView) itemView.findViewById(R.id.textview_activity_item_name);
            loadMoney= (TextView) itemView.findViewById(R.id.text_activity_item_money);
            loadXiaoliang= (TextView) itemView.findViewById(R.id.textview_activity_item_xiaoliang);
        }
    }
}
